package cn.sixmillions.mb.sqlSession;

import cn.sixmillions.mb.config.XMLConfigBuilder;
import cn.sixmillions.mb.pojo.Configuration;

import java.io.InputStream;

/**
 * SqlSession工厂类
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws Exception {

        //1. 解析配置文件（数据源与mapper）
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        //2. 创建sqlSessionFactory对象：工厂类：生产sqlSession:会话对象
        SqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
